package No1_100.No21_30.SwapNodesinPairs_24;

import No1_100.No1_10.AddTwoNumbers_2.ListNode;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public static ListNode swapPairs(ListNode head) {
        ListNode ret = head;
        ListNode l1 = head;
        if (head != null) {
        	 l1 = head.next;
		}
        else {
			return ret;
		}
    	while (head != null && l1 != null) {
    		int temp = l1.val;
    		l1.val = head.val;
    		head.val = temp;
    		head = head.next.next;
    		if (head != null) {
    			l1 = l1.next.next;
			}
		}
        
    	return ret;
    }
    
    public static void main(String args[]) {
		ListNode lsListNode = new ListNode(0);
		ListNode retListNode = lsListNode;
		lsListNode.val = 9;
		ListNode retListNode2 = new ListNode(0);
		retListNode2.val = 7;
		lsListNode.next = retListNode2;

		ListNode retListNode3 = new ListNode(0);
		retListNode3.val = 1;
		ListNode ret = swapPairs(retListNode);
		while(ret!=null){
			System.out.print(ret.val);
			ret = ret.next;
		}
		
		System.out.println("\nok");
		
	}
}
